package logic

import (
	"camera/B/Rpc/model/mysql"
	"context"
	"fmt"

	"camera/B/Rpc/camera"
	"camera/B/Rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *camera.UserListRequest) (*camera.UserListResponse, error) {
	// todo: add your logic here and delete this line
	u := mysql.User{}
	user, err := u.GetUser(int(in.Status), int(in.Page), int(in.PageSize))
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}

	var userlist []*camera.UserList
	for _, u2 := range user {
		userlist = append(userlist, &camera.UserList{
			Phone:    u2.Phone,
			Password: u2.Password,
			Status:   int64(u2.Status),
		})
	}
	return &camera.UserListResponse{
		Userlist: userlist,
	}, nil
}
